<template>
  <div>
    <el-dialog title="岗位变更" v-bind="$attrs" v-on="$listeners">
      <el-row
        :gutter="30"
        class="main"
        :style="{ margin: '0 auto', width: '100%' }"
      >
        <el-form
          :model="dataForm"
          ref="elForm"
          size="mini"
          label-width="100px"
          :rules="rules"
        >
          <el-col :span="24">
            <el-form-item label="变更时间:" prop="changetime">
              <el-date-picker
                style="width: 329px"
                v-model="dataForm.changetime"
                placeholder="请选择"
                clearable
                type="date"
                format="yyyy-MM-dd"
                value-format="timestamp"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="原所属部门:" prop="originaldepartment">
              <dep-select
                v-model="dataForm.originaldepartment"
                placeholder="请选择原所属部门"
              >
              </dep-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="原所属岗位:" prop="originaljob">
              <pos-select
                v-model="dataForm.originaljob"
                placeholder="请选择原所属岗位"
                :multiple="false"
              >
              </pos-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="现所属部门:" prop="departmentafterchange">
              <dep-select
                v-model="dataForm.departmentafterchange"
                placeholder="请选择现所属部门"
              >
              </dep-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="现所属岗位:" prop="jobafterchange">
              <pos-select
                v-model="dataForm.jobafterchange"
                placeholder="请选择现所属岗位"
                :multiple="false"
              >
              </pos-select>
            </el-form-item>
          </el-col>
          <!-- <el-col :span="18">
            <el-form-item label="上传附件:">
              <el-input v-model="dataForm.c"></el-input
            ></el-form-item>
          </el-col> -->
        </el-form>
      </el-row>
      <span slot="footer">
        <el-button type="text" @click="$emit('update:visible', false)"
          >取消</el-button
        >
        <el-button type="primary" @click="submit" :loading="btnloading"
          >确定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>
<script>
import request from "@/utils/request";
import { updateUser, getUserInfo } from "@/api/permission/userXy";
export default {
  name: "",
  data() {
    return {
      btnloading: false,
      dataForm: {
        changetime: "",
        originaldepartment: "",
        departmentafterchange: "",
        originaljob: "",
        jobafterchange: "",
      },
      rules: {
        changetime: [
          {
            required: true,
            message: "请选择时间",
            trigger: "change",
          },
        ],
        originaldepartment: [
          {
            required: true,
            message: "请选择原所属部门",
            trigger: "change",
          },
        ],
        departmentafterchange: [
          {
            required: true,
            message: "请选择现所属部门",
            trigger: "change",
          },
        ],
        originaljob: [
          {
            required: true,
            message: "请选择原所属岗位",
            trigger: "change",
          },
        ],
        jobafterchange: [
          {
            required: true,
            message: "请选择现所属岗位",
            trigger: "change",
          },
        ],
      },
      dataForm1: {},
    };
  },
  methods: {
    submit() {
      this.$refs.elForm.validate((valid) => {
        if (valid) {
          this.dataForm1.xy_hse_ar_jobtransferrecordEntityList.push(
            this.dataForm
          );
          this.btnloading = true;
          updateUser(this.dataForm1)
            .then((res) => {
              this.$message({
                message: res.msg,
                type: "success",
                duration: 1000,
                onClose: () => {
                  this.$emit("update:visible", false);
                  this.btnloading = false;
                  for (let i in this.dataForm) {
                    this.dataForm[i] = "";
                  }
                },
              });
            })
            .catch(() => {
              this.btnloading = false;
            });
        }
      });
    },
    initData(id) {
      this.$nextTick(() => {
        this.$refs.elForm.clearValidate();
        getUserInfo(id,this.$store.getters.organizeId).then((res) => {
          this.dataForm1 = res.data;
          this.dataForm1.xy_hse_ar_jobtransferrecordEntityList = this.dataForm1
            .xy_hse_ar_jobtransferrecordEntityList
            ? this.dataForm1.xy_hse_ar_jobtransferrecordEntityList
            : [];
        });
      });
    },
  },
};
</script>
<style scoped lang='less'>
</style>